package com.yuke.cloud.service.uac.job;

import com.yuke.cloud.service.uac.entity.AccEmployeeGroup;
import com.yuke.cloud.service.uac.service.AccEmployeeGroupService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.scheduling.annotation.EnableScheduling;
import org.springframework.scheduling.annotation.Scheduled;
import org.springframework.stereotype.Component;
import tk.mybatis.mapper.entity.Example;

import javax.annotation.Resource;
import java.util.Date;
import java.util.List;

/*
 * <p>Company: Copyright (c) 2018. yuke All Rights Reserved. </br> </p>
 * <p>Title：yuke-mall </br> </p>
 * <p>com.yuke.cloud.service.wmc.job Description TODO </br> </p>
 * @Author wg
 * @Date   2019/10/19 14:06
 */
@Component
@Slf4j
@EnableScheduling
public class employeeQuartz
{

    @Resource
    private AccEmployeeGroupService accEmployeeGroupService;
    /**
     * 每天0点，操作司机为休息状态
     */
    @Scheduled(cron = "0 0 0 * * ?")  // 每天凌晨0点进行
    public void employeeChange() {
        System.out.println("操作司机为休息状态");
        Example example = new Example(AccEmployeeGroup.class);
        Example.Criteria criteria = example.createCriteria();
        criteria.andCondition("(employee_type = 2 or employee_type = 3)");
        criteria.andEqualTo("employeeStatus",(byte)1);
        List<AccEmployeeGroup> employeeList = accEmployeeGroupService.selectByExample(example);

        if (employeeList!=null && employeeList.size()>0) {
            for (AccEmployeeGroup item : employeeList) {
                item.setEmployeeStatus((byte)0);
                item.setUpdateTime(new Date());
                accEmployeeGroupService.update(item);
            }

        }

    }
}
